package io.gitee.chearnee.fw.datasecurity.core.executor;


import io.gitee.chearnee.fw.datasecurity.core.handler.CodecFieldValueHandler;
import org.springframework.util.StringUtils;

/**
 * 默认加解密执行者
 *
 * @author kamjin1996
 */
public class DefaultCryptExecutor implements CryptExecutor {

    private CodecFieldValueHandler codecFieldValueHandler;

    public void setCodecFieldHandler(CodecFieldValueHandler codecFieldValueHandler) {
        this.codecFieldValueHandler = codecFieldValueHandler;
    }

    public DefaultCryptExecutor(CodecFieldValueHandler codecFieldValueHandler) {
        this.codecFieldValueHandler = codecFieldValueHandler;
    }

    @Override
    public String encrypt(String str) {
        if (!StringUtils.hasText(str)) {
            return str;
        }
        return codecFieldValueHandler.encrypt(str);
    }

    @Override
    public String decrypt(String str) {
        if (!StringUtils.hasText(str)) {
            return str;
        }
        return codecFieldValueHandler.decrypt(str);
    }
}
